ig.module(
	'game.entities.optionButton'
)
.requires(
	'impact.entity',
        'game.entities.base.baseButton'  
)
.defines(function()
{
    EntityOptionButton = EntityBaseButton.extend(
    {
        size: {x:586, y:70},

        font: new ig.Font('media/fonts/arial12.png'),
        font16: new ig.Font('media/fonts/arial16.png'),	
        normalButton: new ig.Image("media/images/questionNormal.png"),
        overButton: new ig.Image("media/images/questionOver.png"),
        selectedButton: new ig.Image("media/images/questionSelected.png"),
        
	selectable: true,
        option: 0,
        text: "--text--",
	textOptionOffset: {x:26, y:24},	
        textOffset: {x:85, y:4},
        
	init: function(x, y, settings)
	{
	    this.parent(x, y, settings);	    
	},
	
        onClick: function()
        {
            this.parent();            
        },
        
	onSelect: function()
	{
	    this.parent();
            
	    var options = ig.game.getEntitiesByType(EntityOptionButton);
            
            for (var i =0; i < options.length; ++i)
            {
                options[i].selected = false;
            }
            
            this.selected = true;
            
            ig.global.fullQuestion[ig.global.currentQuestion].userAnswer = this.option;
	},
        
        draw: function()
        {
            this.parent();
	    
	    var textOption = "?)";
	    switch (this.option)
	    {
		case 1:
		    textOption = "A)"
		    break;

		case 2:
		    textOption = "B)"
		    break;
		
		case 3:
		    textOption = "C)"
		    break;
		
		case 4:
		    textOption = "D)"
		    break;		
	    }
	    
            this.font16.draw(textOption, this.pos.x + this.textOptionOffset.x, this.pos.y + this.textOptionOffset.y, ig.Font.ALIGN.LEFT);    	    
            this.font.draw(this.text, this.pos.x + this.textOffset.x, this.pos.y + this.textOffset.y, ig.Font.ALIGN.LEFT);                        
        },
	
	ajustOptionString: function (questionText)
	{
	    var bufferText = "";
	    var words = questionText.split(' ');
	    
	    var currentWidth = 0;
	    for (var i = 0; i <	words.length; ++i)
	    {
		currentWidth += this.font.widthForString(words[i] + " ");
		
		if (currentWidth >= 200)
		{
		    bufferText += "\n";
		    currentWidth = 0;
		}
		
		bufferText += words[i] + " ";
	    }

	    return bufferText;
	}	
    });
});